# -*- coding: utf-8 -*-
from datetime import timedelta
from jms.dwd.dwd_warhouse.dwd_wide_sign_trace_waybill_step_dt import jms_dwd__dwd_wide_sign_trace_waybill_step_dt_new
from jms.dwd.tab.dwd_barscan_unloading_dt import jms_dwd__dwd_barscan_unloading_dt
from jms.dwd.tab.dwd_tab_barscan_send_base_dt import jms_dwd__dwd_tab_barscan_send_base_dt
from jms.dwd.tms.dwd_tmsnew_shipment_union_base_dt import jms_dwd__dwd_tmsnew_shipment_union_base_dt

from jms.time_sensor.time_after_05_00 import time_after_05_00
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dm__dm_tab_cn_center_scan_lack_total_dt = SparkSqlOperator(
    task_id='jms_dm__dm_tab_cn_center_scan_lack_total_dt',
    email=['shenjiaming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_tab_cn_center_scan_lack_total_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_tab_cn_center_scan_lack_total_dt/execute.hql',
    driver_cores=4,
    driver_memory='20G',
    executor_cores=4,
    executor_memory='12G',
    num_executors=40,
    pool_slots=10,
    pool='unlimited_pool',
    # num_executors=10,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.maxExecutors': '80',
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',
          'spark.dynamicallocation.enabled': 'true',
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': '600',
          'spark.shuffle.service.enabled': 'true',
          'spark.sql.shuffle.partitions': '320',
          'spark.driver.maxResultSize': '12G',
          'spark.sql.broadcastTimeout': '3600',
          'spark.yarn.executor.memoryOverhead': '12G',
          'spark.core.connection.ack.wait.timeout': '600',
          'spark.shuffle.file.buffer': '64',
          'spark.reducer.maxSizeInFlight': '96',
          'spark.shuffle.io.maxRetries': '6'
          },
    # hiveconf={'hive.exec.dynamic.partition': 'true',
    #           'hive.exec.dynamic.partition.mode': 'nonstrict',
    #           'hive.exec.max.dynamic.partitions.pernode': '200',
    #           'hive.exec.max.dynamic.partitions': '200',
    #           'hive.optimize.bucketmapjoin': 'true',
    #           'hive.optimize.bucketmapjoin.sortedmerge': 'true',
    #           'hive.input.format': 'org.apache.hadoop.hive.ql.io.BucketizedHiveInputFormat',
    #           'hive.auto.convert.sortmerge.join': 'true',
    #           'hive.auto.convert.sortmerge.join.noconditionaltask': 'true'
    #           },
    yarn_queue='pro',
    retries=0,
    execution_timeout=timedelta(minutes=60),
)

jms_dm__dm_tab_cn_center_scan_lack_total_dt << [
    jms_dwd__dwd_wide_sign_trace_waybill_step_dt_new
    , jms_dwd__dwd_barscan_unloading_dt
    , jms_dwd__dwd_tab_barscan_send_base_dt
    , jms_dwd__dwd_tmsnew_shipment_union_base_dt
    , time_after_05_00
]
